package com.gm.wholesale.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.gm.commonlib.views.toast.ToastUtil;
import com.gm.wholesale.module.wx.share.WXShareUtil;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.youth.banner.util.LogUtils;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WXShareUtil.getIWXAPI(this).handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        WXShareUtil.getIWXAPI(this).handleIntent(getIntent(), this);
    }

    @Override
    public void onReq(BaseReq baseReq) {
        LogUtils.d("微信：onReq" + baseReq.toString());
    }

    @Override
    public void onResp(BaseResp baseResp) {
        switch (baseResp.errCode) {
            // 正确返回
            case BaseResp.ErrCode.ERR_OK:
                ToastUtil.showToast("分享成功");
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                ToastUtil.showToast("取消分享");
                break;
            default:
        }
        finish();
    }
}
